home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-16 | 54.0 KB | 1,952 lines | [TEXT/MPS ] |
- #include <Controls.h>
- #include <Devices.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Errors.h>
- #include <Files.h>
- #include <Memory.h>
- #include <Strings.h>
- #include <Types.h>
- #include <ToolUtils.h>
- #include <Packages.h>
- #include <Resources.h>
- #include <SysEqu.h>
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <OSEvents.h>
- #include <Folders.h>
-
- #include "cdev.h"
- #include "TracksSaveLoad.h"
-
- // Copyright 1990, 1991 Orion Network Systems, Inc. All Rights Reserved.
-
-
- pascal long cdevMain(short msg,short item,short nitems,short id,
- EventRecord *event, t_cdev *object, WindowPeek theDialog)
- {
- long result;
- if (msg == macDev)
- return true ; /* Always runnable */
- if (msg == initDev)
- {
- object =(t_cdev*) NewPtrClear(sizeof(t_cdev)); // Allocate the class
- if ( object != nil )
- {
-
- object->fDp = theDialog;
- object->fWindRefnum = theDialog->windowKind;
- object->fRsrcID = id;
- object->fLastItem = nitems;
- }
- }
- if (object != nil) // Test for failure
- {
- object->fEvent = event;
- result = object->Message(msg, item);
- if (result == 0) // Close the cdev now. (other close stuff already done )
- {
- DisposPtr((Ptr)object);
- return false ;
- }
- }
- return((long) object);
- }
-
- /**************************************************************
-
- Function: Cdev Message Activate:
- Activates the scroll bar
-
- **************************************************************/
-
- void t_cdev::Activate(void) /* "activDev" */
- {
- /* Activate Scroll Bars and any controls... */
- if (fScrollBar != 0L && fInCDEVMode)
- DEnableControl(fScrollBar, true); /* We send the actual control handle, not the item # */
- }
-
-
- /**************************************************************
-
- Standard Cut,Copy,Paste etc. routines... Not used here.
-
- **************************************************************/
-
- void
- t_cdev::CmdKey(short c)
- {
- switch (c) {
- case 'z': case 'Z':
- break;
- case 'x': case 'X':
- break;
- case 'c': case 'C':
- break;
- case 'v': case 'V':
- break;
- }
- }
-
- /**************************************************************
-
- Name: CdevMaskToDriver
-
- Type: Procedure Implementation
-
- Function: Sends the mask we have (fBreakMask or fTraceMask) to the driver
- so that it can selectivly collect data coming in.
- Also send the "BreakOnceThenClear" Boolean to the .TRACE driver
- Inputs: kGetCdevBreakMask or kGetCdevTraceMask
-
- Globals:
-
- Output:
-
- Side Effects:
-
- **************************************************************/
- OSErr t_cdev::CdevMaskToDriver(short csCode)
- {
- TraceParamBlock tpb;
- OSErr result;
- tpb.u.mask.BreakOnce=1; // Gets rid of warning-- (use pragma)
- if (fInCDEVMode)
- {
- if (csCode == kGetCdevBreakMask)
- DoCopyMask(fBreakMask,tpb.u.mask.Mask);
- else
- if (csCode == kGetCdevTraceMask)
- DoCopyMask(fTraceMask,tpb.u.mask.Mask);
- tpb.u.mask.BreakOnce = fBreakOnceThenClear;
- result = Control(fTraceRefNum, csCode, (Ptr) &tpb);
- ReportResult(result,kDriverError);
- } else result = noErr; // Dont want to set off any alarms here
- return result;
- }
-
- // unused
- void t_cdev::Error(long code)
- {
- fStatus = code;
- }
-
- /**************************************************************
-
- ChangeBank
-
- Function: changes the scroll window (area) to another set of mask names...
- It also sets the fMaskIndex to the new window, so check mark hits will change the
- proper bits...
- A bank number is the number that represents the list of scrollable mask names
- that is showing in the scroll window-- ie a page number... (0-7 or 0-15)
-
-
- Inputs: New bank number- (changed by the scroll bar...)
-
-
- **************************************************************/
-
- void t_cdev::ChangeBank(short NewBankNumber)
- {
- if (NewBankNumber < fMinBankSize) NewBankNumber = fMinBankSize;
- if (NewBankNumber > fMaxBankSize) NewBankNumber = fMaxBankSize;
-
- if (NewBankNumber == fMaskIndex) return; // Already set right..
- fMaskIndex = NewBankNumber;
- UpdateFields(); /* Check the right boxes etc.. */
- }
-
- /**************************************************************
-
- Name: CheckMarkHit
- Function: Yes, it handles checkmark hits... If the option
- key is down, it calls DebugMarkHit. A checkmark sets or
- clears the Trace mask and sends the mask to the driver.
-
- **************************************************************/
-
-
- /* Flip the value of the checkmark that is hit- ie toggle that checkmark and
- ** update the mask that the driver sees...
- */
-
- void t_cdev::CheckMarkHit(short itemHit)
- {
- short BitPos;
- Boolean BitIsSet;
- shex WhichBitOf128; // Although it says 128 here, it should work with different
- // sized masks...
-
-
- /* fMaskIndex is which page of names we are in... depending on fInCDEVMode */
-
- BitPos = (itemHit - fChecks_Start);
-
- WhichBitOf128 = BitPos + (fMaskIndex * fFieldsPerBank); /* Produces a number between 0-127 */
- if (WhichBitOf128 > kBitsPerMask)
- {
- // DebugStr("\pCheckHitErr"); // This hasnt happened yet, I don't expect it to.
- return;
- }
- if (fEvent->modifiers & optionKey)
- {
- DebugMarkHit(BitPos);
- }
- else
- {
- BitIsSet = BitTst((Ptr)fTraceMask,(long)WhichBitOf128);
- DSetControl(itemHit,!BitIsSet); /* Reverse it.. */
- if (BitIsSet)
- BitClr((Ptr)fTraceMask,(long)WhichBitOf128);
- else
- BitSet((Ptr)fTraceMask,(long)WhichBitOf128);
- CdevMaskToDriver(kGetCdevTraceMask); /* Send the new Mask to the Driver... */
- }
- }
-
- /**************************************************************
-
- Function: Calls .TRACE Driver with instruction to clear trace buffer.
-
- **************************************************************/
-
- void t_cdev::ClearBufferNow()
- {
- register short result;
-
- result = Control(fTraceRefNum, kClearTraceBuffer,nil);
- DSetLong(iBufferSizeStatic,fTraceStatus.bufferSize); /* Show buffer size: */
- ReportResult(result,kDriverError);
- }
-
- /**************************************************************
-
- Called when cdev is closed by user... deallocates memory.
-
- **************************************************************/
-
- void t_cdev::Close()
- {
- DoSave(0); // save user prefs
-
- if (fFieldNames != nil)
- DisposHandle(fFieldNames); // dispose the STR# type list
- fFieldNames = nil;
- ReleaseResource((Handle)fBugPicture);
- // (this) is disposed of in cdevMain.cp
-
- }
-
- /**************************************************************
-
- Copies a mask... All 128 bits...
-
- **************************************************************/
-
- void t_cdev::DoCopyMask(MaskType src, MaskType dst)
- {
- BlockMove((Ptr)src,(Ptr)dst,sizeof(MaskType));
- }
-
- /**************************************************************
-
- Cdev Message-- Handle Deactivate message. Deactivate scroll bar
- so it turns white.
-
- **************************************************************/
- void t_cdev::Deactivate(void) /* "deactiveDev" */
- {
- if (fScrollBar != 0L && fInCDEVMode)
- /* Deactivate Scroll Bars */
- DEnableControl(fScrollBar, false); /* Send the ControlHandle to be deactivated */
- }
-
- /**************************************************************
-
- Flip the value of the checkmark that is hit- ie toggle that checkmark and
- update the mask that the driver sees.. The sister routine
- of this is CheckMarkHit.
-
- **************************************************************/
-
- void t_cdev::DebugMarkHit(short BitPos)
- {
- Boolean BitIsSet;
- shex WhichBitOf128; // Will work if mask size changes...
- register snum result;
-
- /* fMaskIndex is which element in this array we are in... */
-
- WhichBitOf128 = BitPos + (fMaskIndex * fFieldsPerBank); /* Produces a number between 0-127 */
-
-
- BitIsSet = BitTst((Ptr)fBreakMask,(long)WhichBitOf128);
- if (BitIsSet)
- BitClr((Ptr)fBreakMask,(long)WhichBitOf128);
- else
- BitSet((Ptr)fBreakMask,(long)WhichBitOf128);
-
- DrawABug(BitPos,!BitIsSet); /* Draw it or erase it, which ever it is not */
-
- result = CdevMaskToDriver(kGetCdevBreakMask);
- ReportResult(result,kDriverError);
- }
-
-
- /**************************************************************
-
- DEnableControl enables or disables a control....
-
- **************************************************************/
- void t_cdev::DEnableControl(ControlHandle Control,Boolean Enable)
- {
-
- /* Enable/Disable scroll bar... This would work for normal buttons too */
- if (Enable)
- HiliteControl(Control,0); /* Enable item */
- else
- HiliteControl(Control,255); /* Disable */
- }
-
- /**************************************************************
-
- Gets an item and enables it. Correctly handles cdev DITL's.
-
- **************************************************************/
-
- void t_cdev::DEnableItem(short theitem,Boolean Enable)
- {
- Handle Control;
- Rect arect;
- short itemtype;
- GetDItem((GrafPort *)fDp, theitem + fLastItem, &itemtype, &Control, &arect);
- DEnableControl((ControlHandle)Control,Enable);
- }
-
- /**************************************************************
-
- Gets the frame of a DITL Item..
-
- **************************************************************/
-
- void t_cdev::GetDItemFrame(short item,Rect *r)
- {
- short ItemType;
- Handle ItemHandle;
- GetDItem((GrafPort *)fDp, fLastItem + item , &ItemType, &ItemHandle, r);
- }
-
- /**************************************************************
-
- Loads a preference file, with the name of 'STR ' -4063, which
- is currently 'Tracks prefs'.
-
- Reads the name of the driver file that user wants to trace.
- That file is opened, and two resources are extracted. One, the
- name of the driver (usually preceded by a .), and a list of the
- names of the trace points.
-
- **************************************************************/
-
- void t_cdev::DoLoad()
- {
- saveTypeHandle hSave;
- register short PrefsResRefNum;
- register short err;
- StringHandle PStrHand;
- Boolean wasError;
- short prefsFolderVol;
-
- wasError = false; // unless otherwise set...
- // Get Pref File Name
-
- PStrHand = GetString(-4063); /* Name of Preference file */
- err = ResError();
- if (PStrHand == nil) // There was no preference file... Reset the trace...
- wasError = true;
- else
- {
- // Open Tracks Prefs file
- HLock((Handle)PStrHand);
- prefsFolderVol = GetFolderVol(kPreferencesFolderType);
-
- PrefsResRefNum = OpenRFPerm((const Str255)*PStrHand, prefsFolderVol, fsRdWrPerm);
-
- HUnlock((Handle)PStrHand);
- err = ResError();
-
- if ((err == noErr) && (PrefsResRefNum != -1))
- {
- // Get fTargetAppName -- eg : "TestDrvr" or whatever your drivers _file_ name is...
- if (fTargetAppName != nil)
- DisposHandle(fTargetAppName);
-
- fTargetAppName = GetResource('kDRp', 128);
- err = ResError();
-
- if (fTargetAppName != nil)
- {
- DetachResource(fTargetAppName);
- } else wasError = true;
-
- // Get Saved preferences
-
- hSave = (saveTypeHandle)GetResource(kPrefResType, kPrefResID);
- err = ResError();
-
- if (hSave != nil) // and there exists a preference file...
- {
- if ((**hSave).Version != kVersionNumber)
- {
- // an old version of prefs is present...
- ReportResult(afpBadVersNum,kFileError);
- CloseResFile(PrefsResRefNum);
- wasError = true;
- }
- else
- {
- // Copy the saved preferences into the proper globals...
-
- DoCopyMask((**hSave).fTraceMask , fTraceMask); // move saved prefs to masks
- DoCopyMask((**hSave).fBreakMask , fBreakMask);
- fBreakOnceThenClear = (**hSave).fBreakOnceThenClear;
- fTraceOnStartup = (**hSave).fTraceOnStartup;
- fBufferSize = (**hSave).fBufferSize = fBufferSize;
- fAutoWriteOn = (**hSave).fAutoWriteOn;
- fCurrentSizeIndex = (**hSave).fCurrentSizeIndex;
- fTraceEnabled = (**hSave).fTraceEnabled;
- ReleaseResource((Handle)hSave);
- }
- } else wasError = true;
-
- CloseResFile(PrefsResRefNum);
-
- } else
- {
- fTargetAppName = nil; // Make a default table...
- wasError = true;
- }
-
- if (wasError == false)
- GetTargAppStuff(); /* Knowing the name of the driver to be traced, get information from that file... */
-
- ReleaseResource((Handle)PStrHand);
- (void) ResError();
- }
-
- // Try to open the TargetApplication
- if (wasError)
- {
- // Reset the trace....
-
- (void) Control(fTraceRefNum, kSetTraceOffline, nil);
- fTraceEnabled = false;
-
- fTraceOnStartup = false; // turn off trace from startup
- fBreakOnceThenClear = true; // will get sent to drvr by FillMask
-
- (void) Control(fTraceRefNum,kStartedFromInit,(Ptr)fTraceOnStartup);
-
- // FillMask(kBreakMaskID, 0); // Clear Break Mask
- // FillMask(kTraceMaskID, 0); // and trace mask
-
- Control(fTraceRefNum, kSetAutoWriteOff, nil);
- fAutoWriteOn = false;
-
- if (fDriverDotName != nil)
- DisposHandle(fDriverDotName);
- fDriverDotName = GetResource('STR ', -4062); /* <No driver> */
- DetachResource(fDriverDotName);
- LoadFieldNames(); // This will create a field name list on the fly...
- // ReportResult(resNotFound,kFileError);
- }
-
- }
-
- /**************************************************************
-
- given a folder type like 'pref', this will return the vol ref num...
-
- **************************************************************/
- short t_cdev :: GetFolderVol(OSType type)
- {
- WDPBRec wdParamBlock; /*param block to set up working directory*/
- short result;
- short prefVRef;
- long prefDirID;
-
- result=FindFolder(kOnSystemDisk, type, true, &prefVRef, &prefDirID);
- if (result == 0)
- {
- wdParamBlock.ioCompletion = NULL;
- wdParamBlock.ioNamePtr = NULL;
- wdParamBlock.ioVRefNum = prefVRef;
- wdParamBlock.ioWDDirID = prefDirID;
- result=PBOpenWD(&wdParamBlock, false);
- if (result == 0)
- return wdParamBlock.ioVRefNum;
- }
- return 0;
- }
-
- /**************************************************************
-
- GetTargAppStuff gets the name of the target driver and the str#
- list from the target drivers file...
-
- **************************************************************/
- void t_cdev :: GetTargAppStuff()
- {
- short AppsResRefNum, err;
- Boolean notVaildName = false;
- short vRef;
-
- if (fTargetAppName == nil) {goto fileNotFound;}
-
- HLock(fTargetAppName);
-
- vRef = GetFolderVol(kSystemFolderType); /* Look in System Folder first */
- if (vRef == 0) vRef = fEnvironment.sysVRefNum;
-
- AppsResRefNum = OpenRFPerm((const Str255)*fTargetAppName, vRef, fsRdWrPerm);
-
-
- if (AppsResRefNum == -1)
- {
-
- if (fEnvironment.systemVersion <= 0x607) goto fileNotFound;
-
- vRef = GetFolderVol(kExtensionFolderType); /* Look in Extensions Folder */
- AppsResRefNum = OpenRFPerm((const Str255)*fTargetAppName, vRef, fsRdWrPerm);
- }
-
- if (AppsResRefNum == -1)
- {
- vRef = GetFolderVol(kExtensionFolderType);
- AppsResRefNum = OpenRFPerm((const Str255)*fTargetAppName, vRef, fsRdWrPerm);
- }
-
- if (AppsResRefNum == -1)
- {
- vRef = GetFolderVol(kControlPanelFolderType);
- AppsResRefNum = OpenRFPerm((const Str255)*fTargetAppName, vRef, fsRdWrPerm);
- }
-
- if (AppsResRefNum == -1)
- {
- goto fileNotFound;
- }
-
- err = ResError();
- if (err != noErr) goto failed;
-
- HUnlock(fTargetAppName);
-
- // Get DotDriverName -- eg : ".ASNA"
- if (fDriverDotName != nil)
- DisposHandle(fDriverDotName);
-
- fDriverDotName = GetResource('DrvN', 128);
- err = ResError();
-
- if (fDriverDotName == nil)
- {
- fDriverDotName = GetResource('STR ', -4062); // currently = <No Driver>
- /* Contains no trace information */
- notVaildName = true;
- }
- DetachResource(fDriverDotName);
-
- LoadFieldNames(); // Will build default table if STR# 777 not there
- CloseResFile(AppsResRefNum);
- err = ResError();
-
- if (notVaildName) goto failed;
-
- ReportResult(0, kDriverError); // report noError
- return;
-
- fileNotFound:
- ReportResult(kInternalMsg, 10); // fileNotFound
- return;
-
- failed:
- ReportResult(kInternalMsg, 10); // Driver contains no trace info.
- return;
-
- }
- /**************************************************************
- // Do save saves the following:
- // fTargetAppName: eg Snaps Access.. Whichever driver user is tracing...
- // hSave: Holds other user info
- **************************************************************/
- void t_cdev::DoSave(Boolean JustErasePrefs)
- {
- Handle h;
- register saveTypeHandle hSave;
- register short PrefsResRefNum;
- register short err;
- saveType Prefs;
- Handle PStrHand;
- short prefsFolderVol;
- FInfo finfo;
-
- PStrHand = GetResource('STR ', -4063); // Name of Preference file
- if (PStrHand == nil)
- {
- ReportResult(resNotFound,kFileError);
- return;
- }
- prefsFolderVol = GetFolderVol(kPreferencesFolderType);
- PrefsResRefNum = OpenRFPerm((const Str255)*PStrHand, prefsFolderVol, fsRdWrPerm);
-
- err = ResError();
- if ((err !=noErr) || (PrefsResRefNum == -1))
- {
- if ((err != eofErr) && (err != fnfErr)) // -39 or -43
- {
- ReportResult(err,kFileError);
- return; // We handle only empty resource errors...
- }
-
- SetVol(nil, prefsFolderVol);
- CreateResFile((const Str255)*PStrHand);
-
-
- err = ResError();
- if (err == noErr)
- PrefsResRefNum = OpenRFPerm((const Str255)*PStrHand, prefsFolderVol, fsRdWrPerm);
- err = ResError();
- if (err == noErr)
- {
- GetFInfo((const Str255)*PStrHand, prefsFolderVol, &finfo);
- finfo.fdType = kPrefsOSType;
- finfo.fdCreator = kCDEVCreator;
- SetFInfo((const Str255)*PStrHand, prefsFolderVol, &finfo);
- }
- }
- else
- if (err == noErr)
- { // There are resources present...
- h = GetResource(kPrefResType, kPrefResID);
- if (h != nil) // and there exists a preference file...
- {
- RmveResource(h);
- DisposHandle(h); // and ditch the memory
- }
-
- h = GetResource('kDRp', 128); // The Targ App's Name
- if (h != nil) // and there exists a preference file...
- {
- RmveResource(h);
- DisposHandle(h); // and ditch the memory
- }
-
- UpdateResFile(PrefsResRefNum);
- }
-
- // ready to create and add our own resoruce...
- err = ResError(); // Clear ResError so cdev won't bail
-
- hSave = (saveTypeHandle)NewHandleClear((long)sizeof(saveType));
- if (hSave == nil)
- {
- ReportResult((short) mFulErr, (short) kFileError); // Unlikly scenario
- CloseResFile(PrefsResRefNum);
- return;
- }
- if (JustErasePrefs == false)
- {
- UpdateTraceStatusBlk();
-
- Prefs.Version = kVersionNumber;
- DoCopyMask(fTraceMask, Prefs.fTraceMask);
- DoCopyMask(fBreakMask, Prefs.fBreakMask);
- Prefs.fBreakOnceThenClear = (fBreakOnceThenClear) ? 1:0;
- Prefs.fTraceOnStartup = (fTraceOnStartup) ? 1:0;
- Prefs.fBufferSize = fTraceStatus.bufferSize;
- Prefs.fCurrentSizeIndex = fTraceStatus.bufferSizeIndex;
-
- Prefs.fAutoWriteOn = fAutoWriteOn;
- Prefs.fTraceEnabled = fTraceEnabled;
- Prefs.fUnused1 = nil;
- Prefs.fUnused2 = nil;
- Prefs.fUnused3 = nil;
- Prefs.fUnused4 = nil;
- HLock((Handle)hSave);
- BlockMove((Ptr)&Prefs,(Ptr)*hSave,sizeof(saveType));
- HUnlock((Handle)hSave);
- } // else- empty hSave handle will be saved-- all zeros...
-
- AddResource((Handle)hSave, kPrefResType, kPrefResID, "\pStartup Prefs");
- WriteResource((Handle)hSave);
-
- if (fTargetAppName != nil)
- {
- AddResource(fTargetAppName, 'kDRp', 128, "\pTarget App");
- WriteResource(fTargetAppName);
- }
-
- CloseResFile(PrefsResRefNum); // Updates & closes
- FlushVol(nil, prefsFolderVol);
- ReleaseResource(PStrHand);
- }
- /**************************************************************
- DrawABug
- Draws a bug (breakpoint mark) next to the mask name, to the left of the scroll bar.
- **************************************************************/
- void t_cdev::DrawABug(short bugIndex,Boolean Draw)
- {
- register Rect DrawBugArea,wh,*picRect;
- SetPort((GrafPtr)fDp);
- if ((bugIndex > fFieldsPerBank) || (bugIndex <0)) return; // just in case...
-
- GetDItemFrame(fDebugChecks_Start + bugIndex,&DrawBugArea);
-
- if (Draw)
- {
- HLock((Handle)fBugPicture);
- picRect = &(**fBugPicture).picFrame;
- wh=DrawBugArea;
- OffsetRect(&wh,2,2);
- wh.right = wh.left + (picRect->right - picRect->left);
- wh.bottom = wh.top + (picRect->bottom - picRect->top);
- DrawPicture(fBugPicture,&wh);
- HUnlock((Handle)fBugPicture);
- }
- else
- EraseRect(&DrawBugArea);
- }
-
-
- /**************************************************************/
- // Get the Driver's version of the mask, and put it in our (the cdev's) copy...
- // If whichMask == 1, get the Breakpoint mask.
- // otherwise, get the trace one...
- /**************************************************************/
- OSErr t_cdev::DriverToCdevMask(short csCode)
- {
- TraceParamBlock tpb;
- OSErr result = 0;
- if ((csCode == kSendCdevBreakMask) || (csCode == kSendCdevTraceMask))
- {
- result = Status(fTraceRefNum, csCode, (Ptr) &tpb);
- if (result == 0)
- {
- if (csCode == kSendCdevBreakMask)
- DoCopyMask(tpb.u.mask.Mask,fBreakMask);
- else
- if (csCode == kSendCdevTraceMask)
- DoCopyMask(tpb.u.mask.Mask,fTraceMask);
- fBreakOnceThenClear = tpb.u.mask.BreakOnce; // Breakpoint method
- }
- ReportResult(result,kDriverError);
- } // won't happen..
- return result;
- }
-
- /**************************************************************
- Changes a control (only if it needs to be changed)
- **************************************************************/
- void t_cdev::DSetControl(short theitem,short value)
- {
- ControlHandle Control;
- Rect arect;
- short itemtype;
- short OldValue;
- GetDItem((GrafPort *)fDp, theitem + fLastItem, &itemtype, (Handle *)&Control, &arect);
- SetPort((GrafPort *)fDp);
- if (Control != nil) // just in case
- {
- // Only draw to the screen if it really needs to be drawn
- OldValue = GetCtlValue(Control);
- if (OldValue != value)
- SetCtlValue(Control,value);
- }
- }
- /**************************************************************
-
- Allocates/Deallocates System Heap Space for Trace Buffer...
-
- **************************************************************/
-
- OSErr t_cdev::EnableBuffer(Boolean On)
- {
- short result;
- TraceParamBlock param;
-
- if (On)
- {
-
- result = Control(fTraceRefNum, kDisableTraceBuffer, nil);
-
- param.u.enable.traceBuffSize = fBufSizesHandle[fCurrentSizeIndex];
- param.u.enable.traceBuffSizeIndex = fCurrentSizeIndex;
- result = Control(fTraceRefNum, kEnableTraceBuffer, (Ptr) ¶m);
- if (result != 0)
- {
- return result;
- /* fCurrentSizeIndex =0; Zero Bytes... */
- /* EnableTrace(false); Disable trace, since buffer size is zero.. */
- }
- FlushEvents(everyEvent,0);
- }
- else
- {
- result = Control(fTraceRefNum, kDisableTraceBuffer, (Ptr) ¶m);
- }
-
-
- result = UpdateTraceStatusBlk();
- if (result == 0)
- DSetLong(iBufferSizeStatic,fTraceStatus.bufferSize); /* Show buffer size: */
- fBufferSize = fTraceStatus.bufferSize;
- fBytesBuffered = 0L;
- ReportResult(result,kDriverError); // from last updatetrace...
- return (result);
- }
-
- /**************************************************************
-
- Given a filename and vrefnum, creates this file for trace output
-
- // Changes the file that the trace driver writes to. This is currently not
- // changable by the user... Output is always to the default, which is set once
- // at driver startup time....
-
- **************************************************************/
- OSErr t_cdev::EnableFile(char *fName, short vRefNum)
- {
- short result;
- TraceParamBlock param;
- char fileStr[255];
- param.u.enableFile.fileName = fName;
- param.u.enableFile.vRefNum = vRefNum;
-
- result = Control(fTraceRefNum, kSetTraceFileName, (Ptr) ¶m);
-
- if (result == 0)
- {
- (void) UpdateTraceStatusBlk();
- fBytesWritten = 0L; /* ? */
- }
- ReportResult(result, kDriverError);
- return result;
- }
-
- /**************************************************************
-
- Enables/Disables Trace driver...
-
- **************************************************************/
- OSErr t_cdev::EnableTrace(Boolean On)
- {
- short result;
- if (On)
- {
- if (fDriverDotName != nil)
- result = Control(fTraceRefNum, kSetTraceOnline, (Ptr) *fDriverDotName);
- else result = dInstErr; // driver install error
- }
- else
- result = Control(fTraceRefNum, kSetTraceOffline, nil);
- if (result == 0)
- SetOnOff(On);
- ReportResult(result,kDriverError);
- return result;
- }
-
- /**************************************************************
-
- // This is the extended dialog portion of the cdev... It is a modal dialog that
- // handles events in a similar way that the cdev does- although instead of using ItemHit()
- // it handles its handles button presses, etc inline.
- // The setup required in the beginning saves all cdev varibles that it will modify
- // and then modifies them to conform to the new dialog. This way drawing routines
- // can be used by both the cdev's event handler and this modal dialogs...
- // At the end, the trace is turned back on and the breakpoints/tracepoints are set
- // according to their new values (if any) or if cancel is chosen, the old values
- // are restored.
- //
- // Extended dialog constants use the prefix ke instead of just k.
-
- **************************************************************/
-
- Boolean t_cdev::ExtendedSetup(Ptr saveGlobsPtr)
- {
- Rect extScrollBarRect;
- register SavedGlobalsPtr saveGlobs;
- saveGlobs = (SavedGlobalsPtr)saveGlobsPtr;
- Deactivate(); // Deactivate the cdev before we change fScrollBar
-
- saveGlobs->ScrollBarControl = fScrollBar;
- saveGlobs->MaskIndex = fMaskIndex;
- saveGlobs->DP = fDp;
- saveGlobs->LastItem = fLastItem;
- saveGlobs->InitialTraceState = fTraceEnabled; // On Off State of trace
- saveGlobs->BOTCCopy = fBreakOnceThenClear;
- saveGlobs->TraceStartup = fTraceOnStartup;
- saveGlobs->AutoWriteOn = fAutoWriteOn;
- if (fTraceEnabled)
- {
- EnableTrace(false);
- }
- DoCopyMask(fTraceMask,saveGlobs->TraceMaskCopy); // Save a copy of the masks
- DoCopyMask(fBreakMask,saveGlobs->BreakMaskCopy); // so we can revert.
-
- fDp = (WindowPeek)GetNewDialog(kExtendedDialogID,nil,(WindowPtr)-1);
- if (fDp == nil) return false;
- SetPort((GrafPtr)fDp);
-
- fLastItem = 0;// We no longer have an unknown # of extra D Items (unlike a cdev)
-
- fMinBankSize = keMinBankSize;
- fMaxBankSize = keMaxBankSize;
- fFieldsPerBank = keFieldsPerBank;
- fInCDEVMode = false;
-
- // Position new scroll window
- // fMaskIndex = (saveGlobs->MaskIndex * kFieldsPerBank) % keFieldsPerBank;
- fMaskIndex = 1; // I couldnt get the above line to link. hmph!
-
- fChecks_Start = keChecksStart;
- fChecks_End = keChecksEnd;
- fNames_Start = keNamesStart;
- fNames_End = keNamesEnd;
- fDebugChecks_Start = keDebugAreaStart;
- fDebugChecks_End = keDebugAreaEnd;
- fMaskNumStatic = keMaskNumStatic;
- fErrorMsgStatic = keErrorMsgStatic;
- fErrorNumberStatic = keErrorNumberStatic;
-
-
- /* Get and position Scroll Bar */
- /* Get the size and location of scroll bar (from a user item template) */
-
- GetDItemFrame(keScrollBarArea,&extScrollBarRect); /* Get area of scroll bar (a user item ditl) */
- fScrollBar = NewControl((GrafPort *) fDp,&extScrollBarRect,"\pBigSBar",true,fMaskIndex,
- keMinBankSize, keMaxBankSize,scrollBarProc,0L); /* And create a scroll bar of that size */
- if (fScrollBar == nil) Debugger(); // What can we do? Let it crash...
-
- UpdateFields();
- // Draw anything not handled in the cdev's UpdateFields...
-
- DSetControl(keClearOnceCheckBox,!fBreakOnceThenClear);
- DSetControl (keTraceOnStartup, fTraceOnStartup);
- DSetControl(keAutoWrite,fAutoWriteOn);
-
- MoveTo((*fDp).port.portRect.left,extScrollBarRect.top); // Draw a line across
- LineTo((*fDp).port.portRect.right, extScrollBarRect.top); // The top of the cdev
-
- MoveTo((*fDp).port.portRect.left,extScrollBarRect.bottom-1); // Draw a line across
- LineTo((*fDp).port.portRect.right, extScrollBarRect.bottom-1); // The bottom of the cdev
-
- { // HILIGHT THE OKAY BUTTON
- Rect arect;
- GetDItemFrame(1,&arect);
- PenSize(3,3);InsetRect(&arect,-4,-4);FrameRoundRect(&arect,16,16);PenNormal();
- }
-
-
- return true;
- }
- // see above comments
- void t_cdev::DoExtendedView()
- {
- short itemHit;
- SavedGlobalsPtr saveGlobs;
- Boolean SetUpWorked;
- register short err;
-
- saveGlobs = (SavedGlobalsPtr)NewPtr(sizeof(SavedGlobals));
- if (saveGlobs == nil)
- {
- SysBeep(1);
- return;
- }
- SetUpWorked = ExtendedSetup((Ptr)saveGlobs);
- if (SetUpWorked == false)
- { ExtendedClose((Ptr)saveGlobs);return;}
- HLock((Handle)fScrollBar);
- do
- {
- ModalDialog(nil,&itemHit);
- /**** TRACE MASK NAME HIT (scrollable name hit) *****/
- if (itemHit >= fDebugChecks_Start && itemHit <= fDebugChecks_End)
- {
- DebugMarkHit(itemHit - fDebugChecks_Start);
- }
-
- if (itemHit >=fNames_Start && itemHit <= fNames_End)
- itemHit = fChecks_Start + (itemHit - fNames_Start);
- /*
- ** Change itemHit the value of the check box next to that name.
- ** This is so the user can click on the name of the item,
- ** not the exact location of the check box, to toggle that check box.
- */
-
- /**************** CHECK MARK HIT ********************/
-
- if (itemHit >= fChecks_Start && itemHit <= fChecks_End)
- {
- CheckMarkHit(itemHit);
- }
- switch (itemHit)
- {
- case keScrollBarArea: /*** SCROLL BAR HIT ***/
- // GetMouse(&fEvent->where); (THIS CAUSED ME 1 1/2 DAYS OF ANGUISH!)
- // The above line will cause unpredictability if QuickINIT is installed
-
- HandleScrollBar();
- break;
- case keClearAll:FillMask(kTraceMaskID, 0);break;
- case keSetAll:FillMask(kTraceMaskID, 1);break;
- case keClearBreakPts:FillMask(kBreakMaskID, 0);break;
- case keClearOnceCheckBox:
- fBreakOnceThenClear = !fBreakOnceThenClear;
- DSetControl(keClearOnceCheckBox,!fBreakOnceThenClear);
- break;
- case keAutoWrite:
- fAutoWriteOn = !fAutoWriteOn;
- DSetControl(keAutoWrite,fAutoWriteOn);
- break;
- case keTraceOnStartup:
- fTraceOnStartup = !fTraceOnStartup;
- DSetControl (keTraceOnStartup, fTraceOnStartup);
- // DoSave(0);
- break;
- //case keRevertPrefs:
- // DoSave(true); // true means delete the prefs...
- // break;
- // This is done elsewhere...
-
- default : break;
- }
- } while ((itemHit != 1) && (itemHit !=2));
-
- if (itemHit == keCancelButton)
- {
- DoCopyMask(saveGlobs->TraceMaskCopy,fTraceMask); // CopyMask(src,dest);
- DoCopyMask(saveGlobs->BreakMaskCopy,fBreakMask);
- fBreakOnceThenClear = saveGlobs->BOTCCopy;
- }
- else // Okay button hit-- handle anything that didn't get handled above..
- if (saveGlobs->TraceStartup != fTraceOnStartup)
- {
- err = Control(fTraceRefNum,kStartedFromInit,(Ptr)fTraceOnStartup);
- ReportResult(err,kDriverError);
- fTraceOnStartup = saveGlobs->TraceStartup;
- }
- ExtendedClose((Ptr)saveGlobs);
- // Now out of extended mode- CdevMaskToDriver will allow us to change these...
- CdevMaskToDriver(kGetCdevBreakMask); // Update the breakpoints manually
- CdevMaskToDriver(kGetCdevTraceMask); // And also the trace points
-
- DisposPtr((Ptr)saveGlobs);
- }
- // see above comments
- void t_cdev::ExtendedClose(Ptr saveGlobsPtr)
- {
- register SavedGlobalsPtr saveGlobs;
- saveGlobs = (SavedGlobalsPtr)saveGlobsPtr;
- DisposeControl(fScrollBar);
- fScrollBar = saveGlobs->ScrollBarControl;
- DisposDialog((GrafPtr)fDp);
- fDp = saveGlobs->DP;
- fMaskIndex = saveGlobs->MaskIndex;
- fLastItem = saveGlobs->LastItem;
- fInCDEVMode = true; // Leaving external modal dialog..
-
-
- // SemiConstants reset to small scroll bar environment.
- fFieldsPerBank = kFieldsPerBank;
- fMinBankSize = kMinBankSize;
- fMaxBankSize = kMaxBankSize;
- fChecks_Start = iChecks_Start;
- fChecks_End = iChecks_End;
- fNames_Start = iNames_Start;
- fNames_End = iNames_End;
- fDebugChecks_Start = iDebugChecks_Start;
- fDebugChecks_End = iDebugChecks_End;
- fMaskNumStatic = iMaskNumStatic;
- fErrorMsgStatic = iErrorMsgStatic;
- fErrorNumberStatic = iErrorNumberStatic;
-
- if (saveGlobs->InitialTraceState == true)
- EnableTrace(true);
- if (saveGlobs->AutoWriteOn != fAutoWriteOn)
- {
- // AutoWrite button clicked...
- fAutoWriteOn = !fAutoWriteOn; // change back..
- ToggleAutoWrite(); // and let ToggleAutoWrite change fAutoWrite and all
- }
- Activate(); // Reactivate the cdev's small scroll bar...
- UpdateFields();
- }
-
- //
- // On Entry, WhichMask should equal either kBreakMaskID or kTraceMaskID (the target)
- // If SetCondition == true, then target Mask is set to all 1's.
- // (else, target mask is cleared-- ie no tracepoints set)
- //
-
- void t_cdev::FillMask(short WhichMask, Boolean SetCondition)
- {
- register lhex x;
- register snum result;
-
- if (WhichMask == kBreakMaskID)
- {
- if (SetCondition == true)
- for (x=0;x<kBitsPerMask;x++)
- BitSet((Ptr)fBreakMask,x);
- else
- for (x=0;x<kBitsPerMask;x++)
- BitClr((Ptr)fBreakMask,x);
- }
- else
- {
- if (SetCondition == true)
- for (x=0;x<kBitsPerMask;x++)
- BitSet((Ptr)fTraceMask,x);
- else
- for (x=0;x<kBitsPerMask;x++)
- BitClr((Ptr)fTraceMask,x);
- }
- result = CdevMaskToDriver(kGetCdevTraceMask);
- ReportResult(result,kDriverError);
- UpdateFields();
- }
-
- char *FindNextPStr(char *string)
- {
- char len;
- len = string[0];
- return (string + len + 1);
- }
-
- void t_cdev :: GetFieldName(char *itemName, short index)
- {
- register short x;
- char *namePtr, len;
- short *numStrings;
- char fakeName[100];
- if (fFieldNames == nil)
- *itemName = 0;
- else
- {
- HLock(fFieldNames); // This should be taken out...
- numStrings = (short *)*fFieldNames;
- if ((index) >= *numStrings)
- {
- NumToString(index, (Str255)fakeName);
- namePtr = fakeName;
- }
- else
- {
- namePtr = *fFieldNames;
- namePtr += 2; // Skip past the # of Strings word..
-
- for (x=0;x<index;x++)
- namePtr = FindNextPStr(namePtr);
- }
-
- len = namePtr[0];
- for (x=0;x<len+1;x++)
- {
- itemName[x] = namePtr[x];
- }
- HUnlock(fFieldNames);
- }
- }
- void t_cdev::DGetString(short item,Str255 str)
- {
- short ItemType;
- Handle ItemHandle;
- Rect ItemRect;
-
- GetDItem((GrafPort *)fDp, fLastItem + item , &ItemType, &ItemHandle, &ItemRect);
- SetIText(ItemHandle, str);
- }
-
- void t_cdev::HandleScrollBar(void)
- {
- Point where;
- short part,oldValue,returnCode,newValue;
- register ControlHandle control;
- // Get the location (in LOCAL coords) of where the mouse was.
-
- if (!fInCDEVMode) GetMouse(&where);
- else
- {
- where = fEvent->where;
- GlobalToLocal(&where);
- }
-
-
- if ((fScrollBar == nil) || (*fScrollBar == nil)) // This shouldnt happen
- {
- DebugStr("\pcdev Sbar == 0L!");
- return;
- }
- oldValue = GetCtlValue(fScrollBar);
-
- SetCRefCon(fScrollBar, (long)this ); // Lets our non-object filter get obj stuff
- part = FindControl(where,(GrafPort *)fDp,&control); /* We know this is fScrollBar */
- if (control != nil)
- {
- if (part == inThumb)
- returnCode = TrackControl(control,where,(ProcPtr)0L);
- else
- returnCode = TrackControl(control,where,(ProcPtr)ScrollFilter);
- newValue = GetCtlValue(fScrollBar);
- if (oldValue != newValue)
- ChangeBank(newValue);
- }
- }
-
-
- // The number of bytes buffered changes as data is logged and or written to a file.
- // The cdev needs to make these changes apparent.
- // Also: Now the trace can be turned on and off externally through a dcmd and maybe later
- // through a VBL task type FKEY...
- // The cdev needs to be aware of possible changes and update it's varibles accordingly.
-
- void t_cdev::Idle()
- {
- register short result;
- register long breakMaskCopy[4];
- if (!fInCDEVMode) return;
-
- result = UpdateTraceStatusBlk();
- if (result == noErr)
- {
- if (fBytesBuffered != fTraceStatus.bytesBuffered)
- {
- fBytesBuffered = fTraceStatus.bytesBuffered;
- if (fInCDEVMode) DSetLong(iBytesBuffedStatic,fBytesBuffered);
- }
- if (fBytesWritten != fTraceStatus.bytesWritten)
- { /* Display # of bytes written to disk file */
- fBytesWritten = fTraceStatus.bytesWritten;
- if (fInCDEVMode) DSetLong(iFileSizeStatic,fBytesWritten);
- }
- if (fTraceStatus.DebugMarkUnset)
- {
- DriverToCdevMask(kSendCdevBreakMask); // Get real mask (may or may not be any different
- UpdateFields();
- }
- if (fTraceStatus.online != fTraceEnabled)
- SetOnOff(fTraceStatus.online);
-
- }
- /* We dont call ReportResult here since this is called repeatedly */
- }
-
- OSErr t_cdev::Init()
- {
- register snum Err = noErr,a;
-
-
- SysEnvirons(curSysEnvVers, &fEnvironment);
-
- // SemiConstants-- these only change when going to the extended dialog...
- fFieldsPerBank = kFieldsPerBank;
- fMinBankSize = kMinBankSize;
- fMaxBankSize = kMaxBankSize;
- fChecks_Start = iChecks_Start;
- fChecks_End = iChecks_End;
- fNames_Start = iNames_Start;
- fNames_End = iNames_End;
- fDebugChecks_Start = iDebugChecks_Start;
- fDebugChecks_End = iDebugChecks_End;
- fInCDEVMode = true;
- fMaskNumStatic = iMaskNumStatic;
- fErrorMsgStatic = iErrorMsgStatic;
- fErrorNumberStatic = iErrorNumberStatic;
-
- fScrollBar = 0L;
- SetPort((GrafPtr)fDp);
- fStatus = (long) this; /* So we can get back at our class, globals etc.. from main */
- // Assign possible sizes for the buffer....
-
- a=0; // Do not have more then kMaxNumSizes
-
- // set the possible sizes for the buffer
- fBufSizesHandle[a++] = 0 * 1024;
- fBufSizesHandle[a++] = 4 * 1024;
- fBufSizesHandle[a++] = 8 * 1024;
- fBufSizesHandle[a++] = 16 * 1024;
- fBufSizesHandle[a++] = 32 * 1024;
- fBufSizesHandle[a++] = 96 * 1024;
- fBufSizesHandle[a++] = 256 * 1024;
- fBufSizesHandle[a++] = 512 * 1024;
- fBufSizesHandle[a++] = 1024 * 1024;
- fBufSizesHandle[a++] = 2024 * 1024;
- fBufSizesHandle[a++] = 4024 * 1024;
- fBufSizesHandle[a++] = 8024 * 1024; // Virtual memory support?
-
- fBufferNumSizes = a-1;
-
- fBugPicture = GetPicture(kBugPictureID);
- if (fBugPicture == nil) DebugStr("\pInitPictFail"); // This should close the cdev..
-
- /* Get and position Scroll Bar */
- /* Get the size and location of scroll bar (from a user item template) */
-
- GetDItemFrame(iScrollBarUserItem,&fSBarRect); /* Get area of scroll bar (a user item ditl) */
-
- fScrollBar = NewControl((GrafPort *) fDp,&fSBarRect,"\p",true,0,fMinBankSize,
- fMaxBankSize,scrollBarProc,0L); /* And create a scroll bar of that size */
- if (fScrollBar == nil) DebugStr("\pInitSbarFail");
- ChangeBank((short) 0); /* Set fMaskIndex to zero and draw Mask Names */
-
- DoLoad(); // load user prefs
-
- Err = TraceInit();
- ReportResult(Err,kDriverError);
-
-
- return (Err);
- }
-
- // Handle control item hit
- void t_cdev::ItemHit(short itemHit)
- {
- register short origValue, start, x, bank;
- register short result;
-
- if (itemHit >= fDebugChecks_Start && itemHit <= fDebugChecks_End)
- {
- DebugMarkHit(itemHit - fDebugChecks_Start);
- }
-
- /**** TRACE MASK NAME HIT (scrollable name hit) *****/
-
- if (itemHit >=fNames_Start && itemHit <= fNames_End)
- {
- itemHit = fChecks_Start + (itemHit - fNames_Start);
- /*
- ** Change itemHit the value of the check box next to that name.
- ** This is so the user can click on the name of the item,
- ** not the exact location of the check box, to toggle that check box.
- */
- }
-
-
- /**************** CHECK MARK HIT ********************/
-
- if (itemHit >= fChecks_Start && itemHit <= fChecks_End)
- {
- CheckMarkHit(itemHit);
- return;
- }
- start = 128;
- bank = 32; // Clicking on a button will switch to the start of that group of fields...
- switch (itemHit)
- {
- case iScrollBarUserItem:HandleScrollBar();break; /*** SCROLL BAR HIT ***/
-
- case iConfigFileButton: SetName();break;
- case 24: start -= 32;bank -=8; // Level 4
- case 41: start -= 32;bank -=8; // Level 3
- case 42: start -= 32;bank -=8; // Level 2
- case 43: start -= 32;bank -=8; // Level 1
- // This will set or clear the groups of 32.
- // Group one == 0-31, 2 == 32-63, etc to group 4.
- origValue = BitTst((Ptr)fTraceMask, start);
- if (origValue == true)
- for (x=0;x<32;x++)
- BitClr((Ptr)fTraceMask, x + start);
- else
- for (x=0;x<32;x++)
- BitSet((Ptr)fTraceMask, x + start);
- result = CdevMaskToDriver(kGetCdevTraceMask);
- ReportResult(result,kDriverError);
- UpdateFields();
- // This switches the scroll fields... it may be a little annoying...
- if (origValue == false)
- ChangeBank(bank);
- break;
-
- case iOnChk:
- case iOnMsg: if (!fTraceEnabled) EnableTrace(true);break;
- case iOffChk:
- case iOffMsg: if (fTraceEnabled) EnableTrace(false);break;
-
- case iWriteBufferButton:WriteBufferNow();break;
- case iClearBufferButton:ClearBufferNow();break;
-
- case iAutoWriteChk:
- case iAutoWriteMsg:ToggleAutoWrite();break;
- case iResetEOFButton:ResetEOF();break;
-
- case iSizeIncrement: /* Only allow size changes when off */
- case iSizeDecrement:
- //if (!fTraceEnabled)
- if (TrackItem(itemHit)) SetSize(itemHit);
-
- break;
-
- case iBkptEllipsisButton:DoExtendedView();break; /* Show Help Dialog */
- case iMaskEllipsisButton: // RESET THE TRACE!
- if (fTraceEnabled)
- EnableTrace(false); // disable trace
- fCurrentSizeIndex = kSizeIndexDefault;
- EnableBuffer(true);
- fTraceOnStartup = false; // turn off trace from startup
- fBreakOnceThenClear = true; // will get sent to drvr by FillMask
- (void) Control(fTraceRefNum,kStartedFromInit,(Ptr)fTraceOnStartup);
- FillMask(kBreakMaskID, 0); // Clear Break Mask
- FillMask(kTraceMaskID, 0); // and trace mask
- if (fAutoWriteOn) ToggleAutoWrite(); // turn off periodic write
-
- break;
- default : break;
- }
- }
-
- // This is where we would handle key presses
- void t_cdev::Key(short )
- {
-
- }
-
- // Note: Assumes NewPtrClear was used to create globals..
-
-
- // This is 2 bytes for 0-9, 3 for 10-99, 4 for 100-127
- //#define kFieldHandleSize ((10L * 2L) + (90L * 3L) + (27L * 4L))
- #define kFieldHandleSize 500L // close enough
-
- Boolean t_cdev::LoadFieldNames()
- {
- register long x;
- register Boolean result = true;
- short PrefsResRefNum = 0;
- char len, *pos;
- short err;
-
- if (fFieldNames != nil)
- DisposHandle(fFieldNames);
-
- fFieldNames = GetResource('STR#', kExternalNamesListID);
- err = ResError();
- if (fFieldNames == nil) // We need to create a list of fields for the user.
- {
- fFieldNames = NewHandleClear(kFieldHandleSize);
- if (fFieldNames == nil)
- {
- // we're in deep trouble...
- result = false;
- }
- else
- {
- pos = *fFieldNames; // Create a STR# list of integers 0-127
- pos[0] = 0; // Create a length word...
- pos[1] = 128; // 0x0080 pascal strings...
- pos+=2; // skip past # word...
- for (x=0;x<128L;x++)
- {
- NumToString(x, (Str255)pos);
- len = *pos;
- pos += len+1; // skip past the length byte and the length of the string
- }
- }
- }
- else // Just detach the names...
- DetachResource(fFieldNames);
- return result;
- }
-
- // cdev message dispatching
- long t_cdev::Message(short msg, short item)
- {
- register long result;
- register snum err;
-
- result = 1;
- switch (msg) {
- case initDev:
- err = Init();
- break;
- case hitDev:
- ItemHit(item - fLastItem);
- break;
- case closeDev:
- Close();
- result = 0; /* Signal that we are done... */
- break;
- case nulDev:
- Idle();
- break;
- case updateDev:
- Update();
- break;
- case activDev:
- Activate();
- break;
- case deactivDev:
- Deactivate();
- break;
- case keyEvtDev:
- if (!(fEvent->modifiers & cmdKey))
- Key((unsigned char) fEvent->message);
- else if (fEvent->message != autoKey)
- CmdKey((unsigned char) fEvent->message);
- break;
- case undoDev:
- ;
- break;
- case cutDev:
- ;
- break;
- case copyDev:
- ;
- break;
- case pasteDev:
- ;
- break;
- case clearDev:
- ;
- break;
- }
-
- return(result);
- }
-
-
- /*
- **
- ** ReportResult looks at the result field, and if there is an error (result != 0)
- ** it reports it to the user. It looks in the MsgNum to find the type of problem...
- ** The MsgNum has the Str# equates.
- ** Note: If there wasn't an error, we do not report the kind of error, but use
- ** the kNoError, which is either blank or "noErr", depending on the STR#.
- **
- **
- */
- void t_cdev::ReportResult(short result,short MsgNum)
- {
- Str255 ErrorStr;
- // if (fInCDEVMode == false) return; // No Error Reporting while in extended mode...
- if (result == 0) /* No Error Condition */
- {
- GetIndString(ErrorStr,kTraceErrorsID,kNoErrMsg);
- DSetString(fErrorMsgStatic,ErrorStr); /* Clear Error field or put up noErr msg... */
- DSetLong(fErrorNumberStatic,(long)result);
- }
- else
- {
-
- GetIndString(ErrorStr,kTraceErrorsID,MsgNum);
- if (result == kInternalMsg) /* Internal Error is Blue... */
- {
- ForeColor(blueColor);
- DSetLong(fErrorNumberStatic,0L);
- }
- else /* A driver/OS/file Error has occurred... */
- {
- ForeColor(redColor); /* Let em know in red.. */
- DSetLong(fErrorNumberStatic,(long)result);
- }
-
- DSetString(fErrorMsgStatic,ErrorStr);
- SysBeep(1);
-
- result = 0; /* Makes it easy to spot this from asm. */
-
- ForeColor(blackColor);
- }
- }
-
- // resets data file-- currently this is "Tracks Prefs"
- void t_cdev::ResetEOF()
- {
- register snum result;
- result = Control(fTraceRefNum, kResetEOF, NULL);
- ReportResult(result,kFileError);
- }
-
-
- /* ScrollFilter not included in the class definition,
- ** since filters cant be C++ based..
- */
- pascal void ScrollFilter(ControlHandle SBar,short partCode)
- {
- register t_cdev *Obj;
- register PageAmount;
- Obj = (t_cdev*) GetCRefCon(SBar);
- if (Obj->fKey == kOurKey) // If fkey != kOurKey, the scroll bar has become invalid... dont handle
- {
- if (Obj->fInCDEVMode)
- PageAmount = 4;
- else
- PageAmount = 1; // It's in Extended Dialog- so larger sbar wants smaller page amount
- switch (partCode)
- {
- case inUpButton:Obj->ChangeBank (Obj->fMaskIndex -1);break;
- case inDownButton:Obj->ChangeBank(Obj->fMaskIndex +1);break;
- case inPageUp:Obj->ChangeBank (Obj->fMaskIndex -PageAmount);break;
- case inPageDown:Obj->ChangeBank (Obj->fMaskIndex +PageAmount);break;
- case inThumb:;break;
- default :break;
- }
- }
- return;
- }
- // put a signed decimal long into a dialog item
- void t_cdev::DSetLong(short item,long value)
- {
- Str255 NumStr;
-
- NumToString(value,NumStr);
- DSetString(item,(Str255)NumStr);
- }
-
- // Changes the name of the driver that is being traced.
- // The driver that is to be traced is selected by SFGetFile and that file is opened,
- // and two resources are looked for by GetTargAppStuff().
-
- // A thought was given to the idea of saving the working directory id in the user
- // prefs, so a driver can be in the Extensions folder with system seven...
- // This has not been done. Any file that is used to get the name of the driver and
- // the string list needs to be in the system folder.
-
- void t_cdev::SetName()
- {
- register SFReply reply;
- Point wh;
- StringHandle NewFilePrompt;
- char FileName[32];
- OSType typeList[4];
- short typeCount;
- unsigned char sizeByte;
-
-
- SetPt(&wh,100,40); /* User interface guide!! */
- /* Get a file name and vRefNum from user and pass to Enable File.. */
-
- typeList[1] = 'INIT';
- typeList[0] = 'cdev';
- typeList[2] = 'rsrc'; // lets user create a resource file with the needed info..
-
- // Any file that could have a 'DRVR' resource in it....
- // or a user file with a kDRp resource and a stringlist....
-
- typeCount = 3;
- NewFilePrompt = GetString(-4064); //
- HLock((Handle)NewFilePrompt);
- // Would be nice if it opened to the system Folder
- SetVol(nil, fEnvironment.sysVRefNum);
-
- SFGetFile(wh, (const Str255)*NewFilePrompt, nil, typeCount, typeList, nil, &reply);
-
- HUnlock((Handle)NewFilePrompt);
-
- if (reply.good)
- {
-
- if (fTraceEnabled)
- EnableTrace(false); // turn trace off...
- sizeByte = *reply.fName;
- if (fTargetAppName != nil)
- {
- DisposHandle(fTargetAppName);
- }
- fTargetAppName = NewHandle((long)sizeByte + 1);
- BlockMove((Ptr)reply.fName, (Ptr)*fTargetAppName, (long)sizeByte+1);
- GetTargAppStuff();
-
- UpdateFields();
-
- // InvokeTrace??
- }
- }
-
- /* Sets On Off button of CDEV-- called when Tracks on/off status changes */
- void t_cdev::SetOnOff(Boolean On)
- {
- DSetControl(iOnChk,On);
- DSetControl(iOffChk,!On);
- fTraceEnabled = On;
- }
-
- // Change Buffer Size
- void t_cdev::SetSize(short whichHit)
- {
- OSErr err;
- register short saveIndex;
- register lhex saveSize;
- if (fCurrentSizeIndex & 0xFF00) {fCurrentSizeIndex = 3;} // make sure size index is in check...
-
-
- if ((fBytesBuffered !=0) || fTraceEnabled)
- ReportResult(kInternalMsg,kBufferNotClear);
- else
- {
- saveSize = fBufferSize;
- saveIndex = fCurrentSizeIndex;
-
- if (whichHit == iSizeIncrement)
- if (fCurrentSizeIndex < fBufferNumSizes)
- fCurrentSizeIndex++;
- else {fCurrentSizeIndex = fBufferNumSizes;}
-
- if (whichHit == iSizeDecrement)
- if (fCurrentSizeIndex > 0)
- fCurrentSizeIndex--;
- else {fCurrentSizeIndex = 0;}
-
- err = EnableBuffer(true); // Parameters in fCurrentSizeIndex
- if (err !=noErr) // Try to reset it to what it was...
- {
- fCurrentSizeIndex = fCurrentSizeIndex; // Restore- if pos
- err = EnableBuffer(true);
- if (err) SysBeep(1); // afford to use stronger language here..
- fCurrentSizeIndex = 0; // Reset to zero.. this might help
- }
- (void) EnableBuffer(true);
- }
- }
-
-
- // Draws text to a dialog. fLastItem is the offset to the DITL (if in a cdev)
- // This will draw the text even if the window is not foremost.
- //
- void t_cdev::DSetString(short item, Str255 str)
- {
- Handle StrHandle;
- WindowPeek saveList;
- Rect ItemRect;
- short ItemType;
-
- GetDItem((GrafPort *)fDp, fLastItem + item , &ItemType, &StrHandle, &ItemRect);
- if (StrHandle == nil)
- {return;}
- else
- if (fInCDEVMode) // Move the window to the front, then put back when drawn
- {
- saveList = *((WindowPeek*)WindowList);
- *((WindowPeek*)WindowList) = fDp;
- fDp->windowKind = dialogKind;
- SetPort((GrafPort *)fDp);
- SetIText(StrHandle, str);
- fDp->windowKind = fWindRefnum;
- *((WindowPeek*)WindowList) = saveList;
- }
- else
- {
- SetIText(StrHandle, str);
- }
-
- }
- // Sends message to Tracks driver to turn periodic write to file on
- OSErr t_cdev::ToggleAutoWrite()
- {
- short result;
-
- fAutoWriteOn = !fAutoWriteOn;
- if (fAutoWriteOn)
- result = Control(fTraceRefNum, kSetAutoWriteOn, nil); // param -> nil
- else
- result = Control(fTraceRefNum, kSetAutoWriteOff, nil);
- DSetControl(iAutoWriteChk, fAutoWriteOn);
- ReportResult(result,kDriverError);
- return result;
- }
- // Resets the trace.
- snum t_cdev::TraceInit()
- {
- snum result;
- short prefsVRef;
-
- fKey = kOurKey; // this is to identify our globals
-
- result = OpenDriver("\p.TRACE", &fTraceRefNum);
- if (result != noErr)
- {
- return result; /* Escape now, while you can... */
- }
-
- result = UpdateTraceStatusBlk(); // Updates fTraceStatus
- if (result == 0) /* Set Dialog Items & Enable Buffer and Output file */
- {
- /****************** SET UP BUFFER *******************/
- if ((!fTraceStatus.bufferEnabled))
- {
- fCurrentSizeIndex = kSizeIndexDefault;
- EnableBuffer(true);
- result = UpdateTraceStatusBlk();
- /* we need another account of what the buffersize is */
- }
- fCurrentSizeIndex = fTraceStatus.bufferSizeIndex; /* Index to size of buffer */
- DSetLong(iBufferSizeStatic,fTraceStatus.bufferSize);
-
- /****************** IS IT ON LINE?? ******************/
- SetOnOff(fTraceStatus.online); /* Enable correct ditem for on/off of Trace */
-
- /****************** CHECK THE TRACE OUTPUT FILE ****************/
- prefsVRef = GetFolderVol(kPreferencesFolderType);
- if (prefsVRef == 0)
- prefsVRef = fEnvironment.sysVRefNum;
-
- EnableFile((char *)kDefaultFileName, prefsVRef); // EnableFile is more like a SetFileName.
-
- /***************** Display Status of Periodic Time Option ************/
- fAutoWriteOn = fTraceStatus.autoWrite; /* Set Global to current state */
- DSetControl(iAutoWriteChk,fAutoWriteOn); /* Set AutoWrite checkbox */
-
- /***************** Get Mask & Set appropriate check boxes *******************/
-
- DriverToCdevMask(kSendCdevTraceMask);
- DriverToCdevMask(kSendCdevBreakMask);
- fBreakOnceThenClear = fTraceStatus.breakOnceThenClear;
-
- // these will be reset...
- fBufferSize = fTraceStatus.bufferSize;
- fBytesBuffered = 0L;
- DSetLong(iFileSizeStatic,fBytesWritten);DSetLong(iBytesBuffedStatic,fBytesBuffered);
-
- } /* End Result = 0 */
- UpdateFields();
-
- return result;
- }
-
- // this hilights a pseudo button
- Boolean t_cdev::TrackItem(int item)
- {
- Rect ItemFrame;
- Boolean Inverted=true,InRect;
- Point wh;
- GetDItemFrame(item,&ItemFrame);
- InvertRect(&ItemFrame);
- while (Button())
- {
- GetMouse(&wh);
- InRect = PtInRect(wh,&ItemFrame);
- if ((InRect && !Inverted) || (!InRect && Inverted))
- {
- InvertRect(&ItemFrame);
- Inverted = !Inverted;
- }
- }
- if (Inverted)
- InvertRect(&ItemFrame); /* Don't leave Button hilighted (inverted) */
- return (Inverted); /* If previously inverted, then it was hit and released within */
- }
-
- // respond to an update event
- void t_cdev::Update(void) /* "updateDev" */
- {
- /* Draw thin line above the Scroll bar... */
- if (fInCDEVMode)
- {
- MoveTo(87,fSBarRect.top);
- LineTo(304,fSBarRect.top);
- UpdateFields(); // And fill in all user items and fields
- }
- // Updates for Extended mode are ignored.
- }
-
-
- /* This function fills in the X's in the dialog for the bank index. */
- /* bankvalue has the bit pattern for the current fields */
- /* It also fills in the mask names in the right spaces... */
-
- void t_cdev::UpdateFields(void)
- {
- register shex FieldCount;
- register short index;
- Str255 ItemName;
- register Boolean IsSet;
- Rect r; // For hilighting the Trace Level (1-4)
-
- index = fMaskIndex * fFieldsPerBank; /* Which Mask # from 0-127 */
- if (index >= kBitsPerMask) // won't happen, but just in case...
- {
- fMaskIndex = 0;
- return;
- }
- SetPort((GrafPort *)fDp);
- for (FieldCount=0;FieldCount<fFieldsPerBank;FieldCount++)
- {
- /* Update the Check Marks */
-
- IsSet = BitTst((Ptr)fTraceMask,index+FieldCount);
- DSetControl(fChecks_Start + FieldCount,IsSet);
-
- /* Now Update the Mask Names... */
- GetFieldName((char *)ItemName, index+FieldCount);
- DSetString(fNames_Start+FieldCount, ItemName);
-
- /* And finally, Update the Bug Symbols */
- IsSet = BitTst((Ptr)fBreakMask,index+FieldCount);
- DrawABug(FieldCount,IsSet);
-
- }
- DSetLong(fMaskNumStatic,(long)fMaskIndex * fFieldsPerBank);// Which mask num they are on
- if (GetCtlValue(fScrollBar) != fMaskIndex)
- SetCtlValue(fScrollBar,fMaskIndex);
- if (fInCDEVMode)
- if (fDriverDotName != nil)
- DSetString(iFileNameStatic,(StringPtr)*fDriverDotName);
- else
- { // this handles rare occurances when setup fails to get a driver name to trace..
- fDriverDotName = GetResource('STR ', -4062); // Won't fail...
- DSetString(iFileNameStatic,(StringPtr)*fDriverDotName);
- }
-
- // Hilight the proper trace level buttons (1-4)
- if (fInCDEVMode)
- {
- if (!BitTst((Ptr)fTraceMask, 0)) ForeColor(whiteColor); else ForeColor(greenColor);
- GetDItemFrame(iLevel1Button, &r);
- InsetRect(&r, -2, -2);
- FrameRoundRect(&r,8,8);
-
- if (!BitTst((Ptr)fTraceMask, 32)) ForeColor(whiteColor); else ForeColor(greenColor);
- GetDItemFrame(iLevel2Button, &r);
- InsetRect(&r, -2, -2);
- FrameRoundRect(&r,8,8);
-
- if (!BitTst((Ptr)fTraceMask, 64)) ForeColor(whiteColor); else ForeColor(greenColor);
- GetDItemFrame(iLevel3Button, &r);
- InsetRect(&r, -2, -2);
- FrameRoundRect(&r,8,8);
-
- if (!BitTst((Ptr)fTraceMask, 96)) ForeColor(whiteColor); else ForeColor(greenColor);
- GetDItemFrame(iLevel4Button, &r);
- InsetRect(&r, -2, -2);
- FrameRoundRect(&r,8,8);
- ForeColor(blackColor); // set color back to black...
- }
-
- }
-
- // Gets status of driver... used to detect changes that were not caused from
- // within the cdev-- eg through a dcmd.
- snum t_cdev::UpdateTraceStatusBlk()
- {
- TraceParamBlock param;
- register short result;
-
- param.u.getStatus.statusPtr = &fTraceStatus;
- result = Control(fTraceRefNum, kGetTraceStatus, (Ptr) ¶m);
- fTraceOnStartup = fTraceStatus.TraceOnStartup;
- return result;
- }
-
- // Writes the contents of the buffer to disk.
- void t_cdev::WriteBufferNow()
- {
- TraceParamBlock param;
- register short result;
- result = Control(fTraceRefNum, kWriteTraceBuffer, (Ptr) ¶m);
- ReportResult(result,kFileError);
-
- }
-